package org.dxy.infrastructure.persistent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dxy.infrastructure.persistent.po.query.FactoryViewPo;
import org.dxy.infrastructure.persistent.mapper.FactoryViewMapper;
import org.dxy.infrastructure.persistent.service.FactoryViewService;
import org.springframework.stereotype.Service;

/**
 * 工厂视图服务实现类
 * @author dxy
 * @createTime 2025/8/18
 */
@Service
public class FactoryViewServiceImpl extends ServiceImpl<FactoryViewMapper, FactoryViewPo> implements FactoryViewService {
    
    @Override
    public FactoryViewPo getByFactoryCode(String factoryCode) {
        LambdaQueryWrapper<FactoryViewPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FactoryViewPo::getFactoryCode, factoryCode);
        return getOne(queryWrapper);
    }
    
    @Override
    public boolean existsByFactoryCode(String factoryCode) {
        LambdaQueryWrapper<FactoryViewPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FactoryViewPo::getFactoryCode, factoryCode);
        return count(queryWrapper) > 0;
    }
    
    @Override
    public boolean existsByFactoryCode(String factoryCode, Long excludeId) {
        LambdaQueryWrapper<FactoryViewPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FactoryViewPo::getFactoryCode, factoryCode);
        queryWrapper.ne(FactoryViewPo::getId, excludeId);
        return count(queryWrapper) > 0;
    }
}